﻿using IdentityModel.Client;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;

namespace IdentityClient
{
    class Program
    {
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            Console.WriteLine("Hello IdentityServer4!");
            var client = new HttpClient();
            //var disco = await client.GetDiscoveryDocumentAsync("http://localhost:17491");
            //if (disco.IsError)
            //{
            //    Console.WriteLine(disco.Error);
            //    return;
            //}

            Dictionary<string, string> dict = new Dictionary<string, string>
            {
                ["client_id"] = "OrderServerApiClientId",
                ["client_secret"] = "secret",
                ["grant_type"] = "password",
                ["username"] = "李锋",
                ["password"] = "123456"
            };

            HttpContent content = new FormUrlEncodedContent(dict);

            var tokenResponse = await client.PostAsync("http://47.104.83.210:17491/connect/token", content);

            string result = await tokenResponse.Content.ReadAsStringAsync();

            var tokenResult = JsonConvert.DeserializeObject<TokenResult>(result);
            Console.WriteLine(tokenResult.Access_token);
            Console.ReadKey();
        }
    }
    public class TokenResult
    {
        public string Access_token { get; set; }
        public string Expires_in { get; set; }                                                                                                                             
        public string Token_type { get; set; }
        public string Refresh_token { get; set; }
    }
}
